/****************************************************************************
**  Tite Interactive Text Engine (TiTE)
**  Copyright (C) 2010  Eisoft Group
**
**  This file is part of TiTE.
**
**  TiTE is free software: you can redistribute it and/or modify
**  it under the terms of the GNU General Public License as published by
**  the Free Software Foundation, either version 3 of the License, or
**  (at your option) any later version.
**
**  TiTE is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**  GNU General Public License for more details.
**
**  You should have received a copy of the GNU General Public License
**  along with TiTE.  If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

/*!
 * \file SingletonLifetimeManager_.hpp
 *
 * \date 01/10/2011
 */

#ifndef TITE_CORE_SINGLETON_LIFETIME_MANAGER__HPP
#define TITE_CORE_SINGLETON_LIFETIME_MANAGER__HPP

#include <vector>

#define _TITE_NO_WINDOWS_HEADER
#include <tite/configuration.hpp>
#undef _TITE_NO_WINDWS_HEADER

#include <tite/core/non_copyable.hpp>
#include <tite/core/singleton/singleton_fwd.hpp>

/*!
 * \namespace tite
 *
 * \brief The TiTE namespace.
 */
namespace tite
{
    /*!
     * \namespace core
     *
     * \brief The TiTE core namespace.
     */
    namespace core
    {
        /*!
         * \class SingletonLifetimeManager_ SingletonLifetimeManager_.hpp
         *
         * \brief Manages the deallocation of so-called "managed" singletons;
         *        singletons are automatically registered by specifying the
         *        ManagedLifetime<> template parameter to singleton<>. 
         *
         * \note  Managed singletons are guaranteed to be destroyed upon main()'s return.
         *
         * \author Jason Omahen
         * \version 0.02, 12/18/2010
         */
        class SingletonLifetimeManager_ : private non_copyable
        {
        public:
            typedef deleter_func_t func_t;

            SingletonLifetimeManager_(void);
            ~SingletonLifetimeManager_(void);

            func_t *const registerDeleter(const func_t & deleter, priority_levels::PriorityLevel priority);
            void unregisterDeleter(func_t *const deleterFnPtr);

        private:
            // Attributes
            stdext::vector<func_t *> *m_pSingletonLifetimes[priority_levels::PriorityLevelCount];
        };
    }// End of core namespace
}// End of tite namespace

#endif /* TITE_CORE_SINGLETON_LIFETIME_MANAGER__HPP */